/**
  ******************************************************************************
  * @file           : XYXKC_OTA.h
  * @author         : admin
  * @brief          : None
  * @attention      : None
  * @date           : 2024/8/20
  ******************************************************************************
  */

#ifndef XYXKC_OTA_H
#define XYXKC_OTA_H
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <HTTPClient.h>
#include "Update.h"
typedef std::function<void(size_t, size_t)> THandlerFunction_Progress;
class XYXKC_OTA {
    public:

        XYXKC_OTA(void);

        ~XYXKC_OTA(void);

        void onProgress(THandlerFunction_Progress fu);
        bool update(const String url);
        bool update(const String url, const String token);
        bool update(const String url, const String username, const String password);
        void setVersion(String version);
        String getVersion();
        void restart();
        String getError();
    private:
        String _x_ESP32_version = "XYXKC-1.0.1";
        String _error;
        int http_sendRequest(HTTPClient &http);
        bool http_downloadUpdate(HTTPClient &http, uint32_t size);
        bool runDate(HTTPClient &http);
};
#endif
